<template>
	<view class="content" :style="app_bg">
		<view class="topTitle" :style="'top:'+zhuangtai+'px'">
			<image class="back" @click="backClick" :src="publicimg.btn_back" mode=""></image>
			<view class="" style="font-size: 32rpx;">
				分销中心
			</view>
		</view>
		<view class="top-sreach" :style="'margin-top:'+(zhuangtai+52)+'px;background:'+publicTextColor.app_theme_color+';'">
			<text class="top-title" :style="font_1st">好友人数（{{total_friend}}人）</text>
			<view class="search-input" :style="{background:publicTextColor.app_border_color+';'}">
				<input class="search-input-text" :style="{color:publicTextColor.font_1st_color+';'}" type="text" v-model="keywords" />
				<image @click="selectFunction" class="search-css" src="../../static/search_icon.png" mode=""></image>
			</view>
		</view>
		<view class="tab-list" :style="app_theme">
			<!-- <scroll-view :scroll-x="true" class="money"  style=""> -->
				<view class="" style="display: -webkit-box;">
					<block v-for="(item, index) in tab_list" :key="index">
						<view class="item-text" @click="changeTab(item.id)" 
								:style="{color:(tab_id == item.id?publicTextColor.font_1st_color+';':publicTextColor.font_3rd_color+';'),
										'font-size':tab_id == item.id?'34rpx;':'30rpx;'}">
							{{item.name}}
						</view>
					</block>
				</view>
			<!-- </scroll-view> -->
		</view>
		<view class="user-list" :style="app_theme">
			<block v-for="(item, index) in friend_list" :key="index">
				<view class="item":style="app_border">
					<view class="item-top">
						<image class="friend-avatar" :src="item.avatar" mode=""></image>
						<view class="user-text">
							<text class="font28 text1" :style="font_1st">{{item.nickname}}</text>
							<text class="font24" :style="font_3rd">加入时间：{{item.create_time}}</text>
						</view>
					</view>
					<view class="item-bottom font24" :style="{background:publicTextColor.app_border_color+';',color:publicTextColor.font_3rd_color+';'}">
						<text>{{item.exp}}{{appConfig.exp_name}}</text>
						<view class="line-bottom" :style="font_3rd"></view>
						<text>{{item.game_coin}}{{appConfig.game_coin_name}}</text>
						<view class="line-bottom" :style="font_3rd"></view>
						<text>{{item.gold_coin}}{{appConfig.gold_coin_name}}</text>
						<view class="line-bottom" :style="font_3rd"></view>
						<text>{{item.money}}{{appConfig.money_name}}</text>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				total_friend:0,
				appConfig:'',
				publicTextColor:'',
				publicimg:'',
				zhuangtai:0,
				sign_rules:'',
				tab_id:1,
				page:1,
				size:10,
				level:0,
				keywords:'',
				tab_list:[
					{
						id:1,
						name:'一级好友'
					},
					{
						id:2,
						name:'二级好友'
					},
					{
						id:3,
						name:'三级好友'
					},
					{
						id:0,
						name:'全部好友'
					}
				],
				friend_list:[]
			};
		},
		onShow() {
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		onReachBottom() {
			this.page ++
			this.getSignIndex()
		},
		onLoad() {
			this.setcolorConfig()
			this.getSignIndex()
		},
		computed:{
			user_margin_top(){
				return `margin-top:${(this.zhuangtai+52)}px;background:${this.publicTextColor.app_theme_color};`
			},
			page_top(){
				return `margin-top:${(this.zhuangtai+52)}px;`
			},
			app_border_top(){
				return `border-top:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border_bottom(){
				return `border-bottom:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border(){
				return `border:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_theme(){
				return `background:${this.publicTextColor.app_theme_color};`
			},
			app_bg(){
				return `background:${this.publicTextColor.app_bg_color};`
			},
			font_4th(){
				return `color:${this.publicTextColor.font_4th_color};`
			},
			font_3rd(){
				return `color:${this.publicTextColor.font_3rd_color};`
			},
			font_2nd(){
				return `color:${this.publicTextColor.font_2nd_color};`
			},
			font_1st(){
				return `color:${this.publicTextColor.font_1st_color};`
			}
		},
		methods:{
			selectFunction(){
				this.page = 1
				this.getSignIndex()
			},
			changeTab(id){
				this.tab_id = id
				this.page = 1
				this.getSignIndex()
			},
			getSignIndex(){
				let _self = this
				uni.request({
					url: util.getUrl("distribution/team"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						page:_self.page,
						size:_self.size,
						level:_self.tab_id,
						keywords:_self.keywords
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.total_friend = res.data.data.total_friend
							if(_self.page == 1){
								if(res.data.data.list.length>0){
									_self.friend_list = res.data.data.list
								}else{
									if(_self.keywords != ""){
										uni.showToast({
											title:'未查询到好友！',
											icon:'none'
										})
									}else{
										uni.showToast({
											title:'暂无更多信息！',
											icon:'none'
										})
									}
									_self.keywords = ""
									_self.friend_list = []
								}
							}else if(res.data.data.list.length>0){
								for(let key in res.data.data.list){
									_self.friend_list.push(res.data.data.list[key])
								}
							}else{
								_self.page --
								uni.showToast({
									title:'暂无更多信息！',
									icon:'none'
								})
							}
						}
					},
				});
			},
			setcolorConfig(){
				this.publicTextColor = uni.getStorageSync("diyColor")
				this.publicimg = uni.getStorageSync("diyImg")
				this.appConfig = uni.getStorageSync("appconfig")
			},
			backClick(){
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.user-list{
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 690upx;
		padding: 30upx 30upx 0 30upx;
		box-sizing: border-box;
		border-radius: 20upx;
		.item{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 630upx;
			border-radius: 20upx;
			margin-bottom: 30upx;
			.item-bottom{
				display: flex;
				align-items: center;
				justify-content: space-around;
				width: 100%;
				height: 60upx;
				border-radius: 0 0 20upx 20upx;
				.line-bottom{
					width: 2upx;
					height: 20upx;
				}
			}
			.item-top{
				display: flex;
				align-items: center;
				padding: 22upx;
				width: 100%;
				box-sizing: border-box;
				.user-text{
					display: flex;
					flex-direction: column;
					.text1{
						margin-bottom: 17upx;
					}
				}
				.friend-avatar{
					width: 96upx;
					height: 96upx;
					border-radius: 8upx;
					margin-right: 22upx;
				}
			}
		}
	}
	.tab-list{
		display: flex;
		align-items: center;
		width: 690upx;
		height: 80upx;
		padding: 0 30upx;
		border-radius: 20upx;
		margin-bottom: 30upx;
		.item-text{
			margin-right: 55upx;
		}
		
	}
	.top-sreach{
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 690upx;
		border-radius: 20upx;
		padding: 30upx;
		box-sizing: border-box;
		margin-bottom: 30upx;
		.top-title{
			margin-bottom: 30upx;
		}
		.search-input{
			display: flex;
			align-items: center;
			width: 630upx;
			height: 70upx;
			padding: 0 30upx;
			border-radius: 8upx;
			.search-input-text{
				width: 540upx;
			}
			.search-css{
				width: 32upx;
				height: 32upx;
			}
		}
	}
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		justify-content: center;
		position: absolute;
		z-index: 10;
		width: 100%;
		.back{
			width: 20rpx;
			height: 31rpx;
			position: absolute;
			left: 31rpx;
		}
	}
</style>
